#include "FontMgr.h"

FontMgr FontMgr::instance;
FontMgr::FontMgr(){
}
FontMgr::~FontMgr(){
	for(size_t i=0; i<fonts.size(); ++i){
		if(fonts[i])
			delete fonts[i];
	}
}
size_t FontMgr::loadFont(const std::string& address, unsigned size){
	GLFT_Font* lFont = NULL;
	try{
		lFont=new GLFT_Font(address, size);
		if(vacancies.size()){
			size_t index=vacancies.back();
			vacancies.pop_back();
			fonts[index]=lFont;
			return index;
		}
		else{
			fonts.push_back(lFont);
			return fonts.size()-1;
		}
	}
	catch(std::runtime_error re){
		printf("THE FOLLOWING ERROR OCCURRED:\n");
		printf("%s\n%s%s%s", re.what(),"THE ADDRESS ", address.c_str(), " COULD NOT BE FOUND");
		delete lFont;
		return 0;
	}
}
GLFT_Font& FontMgr::font(size_t index){
	return *(fonts[index]);
}
GLFT_Font& FontMgr::operator[](size_t index){
	return font(index);
}


